#include <gtest/gtest.h>

#include "Rational.h"

TEST(RationalTest, DefaultConstructor)
{
	Rational a;
	EXPECT_EQ(a.numerator(), 0);
	EXPECT_EQ(a.denominator(), 1);
}

TEST(RationalTest, ConstructorWithOneParam)
{
	Rational a(2);
	EXPECT_EQ(a.numerator(), 2);
	EXPECT_EQ(a.denominator(), 1);
}

TEST(RationalTest, ConstructorWithTwoParam)
{
	Rational a(2, 3);
	EXPECT_EQ(a.numerator(), 2);
	EXPECT_EQ(a.denominator(), 3);
}

TEST(RationalTest, CopyConstructor)
{
	Rational a(2, 3);
	Rational b(a);

	EXPECT_EQ(b.numerator(), 2);
	EXPECT_EQ(b.denominator(), 3);
}

TEST(RationalTest, operatorDouble)
{
	Rational a(2, 3);
	EXPECT_EQ(static_cast<double>(a), double(2)/double(3));
}

TEST(RationalTest, operatorAssign)
{
	Rational a(3, 4);
	Rational b;
	b = a;
	EXPECT_EQ(b.numerator(), 3);
	EXPECT_EQ(b.denominator(), 4);
}

TEST(RationalTest, addAssign)
{
	Rational a(1, 8);
	Rational b(3, 8);
	
	b += a;

	EXPECT_EQ(b.numerator(), 1);
	EXPECT_EQ(b.denominator(), 2);
}

TEST(RationalTest, add)
{
	Rational a(1, 8);
	Rational b(3, 8);

	Rational c = a + b;
	
	EXPECT_EQ(c.numerator(), 1);
	EXPECT_EQ(c.denominator(), 2);
}


TEST(RationalTest, minusAssign)
{
	Rational a(1, 8);
	Rational b(3, 8);
	b -= a;

	EXPECT_EQ(b.numerator(), 1);
	EXPECT_EQ(b.denominator(), 4);
}

TEST(RationalTest, minus)
{
	Rational a(1, 8);
	Rational b(3, 8);
	Rational c = b - a;

	EXPECT_EQ(c.numerator(), 1);
	EXPECT_EQ(c.denominator(), 4);
}

TEST(RationalTest, unaryMinus)
{
	Rational a(1, 8);
	Rational b = -a;

	EXPECT_EQ(b.numerator(), -1);
	EXPECT_EQ(b.denominator(), 8);
}

TEST(RationalTest, multAssign)
{
	Rational a(1, 8);
	Rational b(3, 8);
	b *= a;

	EXPECT_EQ(b.numerator(), 3);
	EXPECT_EQ(b.denominator(), 64);
}

TEST(RationalTest, mult)
{
	Rational a(1, 8);
	Rational b(3, 8);
	Rational c = b * a;

	EXPECT_EQ(c.numerator(), 3);
	EXPECT_EQ(c.denominator(), 64);
}

TEST(RationalTest, divAssign)
{
	Rational a(1, 8);
	Rational b(3, 8);
	b /= a;

	EXPECT_EQ(b.numerator(), 3);
	EXPECT_EQ(b.denominator(), 1);
}

TEST(RationalTest, div)
{
	Rational a(1, 8);
	Rational b(3, 8);
	Rational c = b / a;

	EXPECT_EQ(c.numerator(), 3);
	EXPECT_EQ(c.denominator(), 1);
}

TEST(RationalTest, operatorEq_expected_false)
{
	Rational a(1, 8);
	Rational b(3, 8);

	ASSERT_FALSE(a == b);
}

TEST(RationalTest, operatorEq_expected_true)
{
	Rational a(3, 8);
	Rational b(3, 8);

	ASSERT_TRUE(a == b);
}

TEST(RationalTest, operatorNEq_expected_true)
{
	Rational a(1, 8);
	Rational b(3, 8);

	ASSERT_TRUE(a != b);
}

TEST(RationalTest, operatorNEq_expected_false)
{
	Rational a(3, 8);
	Rational b(3, 8);

	ASSERT_FALSE(a != b);
}

TEST(RationalTest, operatorLt_expected_true)
{
	Rational a(1, 8);
	Rational b(3, 8);

	ASSERT_TRUE(a < b);
}

TEST(RationalTest, operatorLt_expected_false)
{
	Rational a(3, 8);
	Rational b(3, 8);

	ASSERT_FALSE(b < a);
}

TEST(RationalTest, operatorLe_expected_true_eq)
{
	Rational a(3, 8);
	Rational b(3, 8);

	ASSERT_TRUE(a <= b);
}

TEST(RationalTest, operatorLe_expected_true_lt)
{
	Rational a(2, 8);
	Rational b(3, 8);

	ASSERT_TRUE(a <= b);
}

TEST(RationalTest, operatorLe_expected_false)
{
	Rational a(4, 8);
	Rational b(3, 8);

	ASSERT_FALSE(a <= b);
}

TEST(RationalTest, operatorGt_expected_true)
{
	Rational a(1, 8);
	Rational b(3, 8);

	ASSERT_TRUE(b > a);
}

TEST(RationalTest, operatorGt_expected_false)
{
	Rational a(3, 8);
	Rational b(3, 8);

	ASSERT_FALSE(b > a);
}

TEST(RationalTest, operatorGe_expected_true_eq)
{
	Rational a(3, 8);
	Rational b(3, 8);

	ASSERT_TRUE(a >= b);
}

TEST(RationalTest, operatorGe_expected_true_lt)
{
	Rational a(2, 8);
	Rational b(3, 8);

	ASSERT_TRUE(b >= a);
}

TEST(RationalTest, operatorGe_expected_false)
{
	Rational a(4, 8);
	Rational b(3, 8);

	ASSERT_FALSE(b >= a);
}

// ---

TEST(RationalTest, NumAndDenomIsNegative)
{
	Rational a(-1, -2);

	ASSERT_EQ(a.numerator(), -1);
	ASSERT_EQ(a.denominator(), -2);
}